
//
//  ReportChoiceCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/5.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "VideoReportChoiceCell.h"

@interface VideoReportChoiceCell ()
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UIImageView *coverImgView;
@property (nonatomic,strong)UIButton *coverBtn;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,assign)NSInteger index;
@property (nonatomic,assign)BOOL isSelected;

@end

@implementation VideoReportChoiceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.font = font(14);
    self.titleLb.textColor = RGBA(51, 51, 51, 1);
    [self.contentView addSubview:self.titleLb];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.centerY.equalTo(self.contentView);
    }];
    
    self.coverImgView = [[UIImageView alloc]init];
    self.coverImgView.image = [UIImage imageNamed:@"common_select_tag"];
    self.coverImgView.highlightedImage = [UIImage imageNamed:@"common_selected_tag"];
    [self.contentView addSubview:self.coverImgView];
    [self.coverImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-16);
        make.size.mas_equalTo(CGSizeMake(14, 14));
        make.centerY.equalTo(self.contentView);
    }];
    
    self.coverBtn = [[UIButton alloc]init];
    [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.equalTo(self);
    }];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(230, 230, 230, 1);
    [self.contentView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)coverMethod{
  
    
    self.isSelected = !self.isSelected;
    
    self.coverImgView.highlighted = self.isSelected;
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectedAtIndex:)]) {
        [self.delegate didSelectedAtIndex:self.index];
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"VideoReportChoiceCell";
    VideoReportChoiceCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[VideoReportChoiceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (void)setContent:(NSString *)content index:(NSInteger)index isSelected:(BOOL)isSelected{
    self.titleLb.text = content;
    self.isSelected = isSelected;
    self.index = index;
    self.coverImgView.highlighted = isSelected;
}
- (void)isHideLine:(BOOL)isHide{
    self.line.hidden = isHide;
}


@end
